package com.summary.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.mapper.SysUserMapper;
import com.summary.domain.Clocking;
import com.summary.domain.vo.UserVO;
import com.summary.mapper.ClockingMapper;
import com.summary.service.IClockingService;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import javax.annotation.Resource;

/**
 * 请假业务Service业务层处理
 *
 * @author NightWalk
 * @date 2023-12-26
 */
@Service
public class ClockingServiceImpl implements IClockingService
{
    @Resource
    private ClockingMapper clockingMapper;

    @Resource
    private SysUserMapper userMapper;


    /**
     * 查询请假业务列表
     *
     * @param
     * @param clocking
     * @return 请假业务
     */
    @Override
    public List<UserVO> selectClockingList(Clocking clocking)
    {
        List<UserVO> userVOList = new ArrayList<>();
        List<SysUser> sysUserList = userMapper.selectUserList1();
        for(SysUser sysUser : sysUserList){
            clocking.setUserId(sysUser.getUserId());
            List<Clocking> clockingList = clockingMapper.selectClockingList(clocking);
            UserVO userVO = new UserVO();
            userVO.setChildClockingList(clockingList);
            userVO.setUserId(sysUser.getUserId());
            userVO.setUserName(sysUser.getUserName());
            userVO.setNickName(sysUser.getNickName());
            userVOList.add(userVO);
        }

        return userVOList;
    }



    /**
     * 新增请假业务
     *
     * @param clocking 请假业务
     * @return 结果
     */
    @Override
    public int insertClocking(@RequestBody Clocking clocking)
    {
        System.out.println(clocking.getNickName());
        SysUser sysUser = userMapper.selectUserByNickName(clocking.getNickName());
        clocking.setUserId(sysUser.getUserId());
        System.out.println(clocking.getUserId());
        return clockingMapper.insertClocking(clocking);
    }

    /**
     * 根据nickName删除请假记录
     *
     * @param
     * @return
     */
    @Override
    public int deleteClockingByNickName(Long clockingId) {
        return  clockingMapper.deleteClocking(clockingId);
    }


    /**
     * 修改用户的请假类型
     * @param clocking
     * @return
     */
    @Override
    public int updateClockingType(Clocking clocking) {
        return clockingMapper.updateClockingType(clocking);
    }

    /**
     * 根据clockingId查询请假记录
     * @param clockingId
     * @return
     */
    @Override
    public Clocking selectOneClockingByClockingId(Long clockingId) {
        return clockingMapper.selectClocking(clockingId);
    }

    @Override
    public int getDayNumber(int month) {
        if (month == 1 || month == 3 || month == 5 || month==7 || month== 8|| month==10 || month==12){
            return 31;
        }
        if (month == 2){
            return 29;
        }
        return 30;
    }
}
